<?php
include_once 'app/until/error.php';

global $GlobError;
	
class MainController extends Error_Codes{

	private $daten;
	public $ModelError;


	public function __construct($match){
		$this->daten = $match;
	}

	public function getWort(RainTPL $design){	
		$conName = $this->getControllerByUrl($this->daten['realurl']);
				
		parent::__construct();
		
		if($conName)
		{
			$this->ModelError = $this->code($conName, $this->daten['error_code']);
		}
		
		if(!$this->ModelError)
		{
			$this->ModelError = "Error Code Unbekannt";
		}
		$_SESSION["GlobError"] = $this->ModelError;
		
	    throw new Exception (GETREAL_CONTROLLER);
	}
	private function getControllerByUrl($url) {
		$temp = $this->getController($url);
		$temp = explode('_', $temp);
		
		return end($temp);
	}
	private function getController($url) {
		$urls = ConfigFile::Get("URL");
		$urls = explode('%', $urls);
		
		for ($i = 1; $i < count($urls); $i = $i+2) {			
			$urls[$i] =	preg_replace('(#\w+#)','',$urls[$i]);
			$urls[$i] =	preg_replace('([\/])','\/',$urls[$i]);
			
			if(preg_match("/^".$urls[$i]."/i",$url))
			{
				return $urls[$i+1];
			}	 
		}
		return false;
	}

}
?>